package com.ruoyi.personnel.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.personnel.domain.EPersonnel;
import com.ruoyi.personnel.mapper.EPersonnelMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.personnel.mapper.ECertificationReviewMapper;
import com.ruoyi.personnel.domain.ECertificationReview;
import com.ruoyi.personnel.service.IECertificationReviewService;

/**
 * 认证审核Service业务层处理
 *
 * @author ruoyi
 * @date 2024-11-24
 */
@Service
public class ECertificationReviewServiceImpl extends ServiceImpl<ECertificationReviewMapper, ECertificationReview> implements IECertificationReviewService
{
    @Autowired
    private ECertificationReviewMapper eCertificationReviewMapper;

    @Autowired
    private EPersonnelMapper ePersonnelMapper;

    /**
     * 查询认证审核
     *
     * @param id 认证审核主键
     * @return 认证审核
     */
    @Override
    public ECertificationReview selectECertificationReviewById(Long id)
    {
        return eCertificationReviewMapper.selectECertificationReviewById(id);
    }

    /**
     * 查询认证审核列表
     *
     * @param eCertificationReview 认证审核
     * @return 认证审核
     */
    @Override
    public List<ECertificationReview> selectECertificationReviewList(ECertificationReview eCertificationReview)
    {
        return eCertificationReviewMapper.selectECertificationReviewList(eCertificationReview);
    }

    /**
     * 新增认证审核
     *
     * @param eCertificationReview 认证审核
     * @return 结果
     */
    @Override
    public int insertECertificationReview(ECertificationReview eCertificationReview)
    {
        eCertificationReview.setCreateTime(DateUtils.getNowDate());
        return eCertificationReviewMapper.insertECertificationReview(eCertificationReview);
    }

    /**
     * 修改认证审核
     *
     * @param eCertificationReview 认证审核
     * @return 结果
     */
    @Override
    public int updateECertificationReview(ECertificationReview eCertificationReview)
    {
        return eCertificationReviewMapper.updateECertificationReview(eCertificationReview);
    }

    /**
     * 批量删除认证审核
     *
     * @param ids 需要删除的认证审核主键
     * @return 结果
     */
    @Override
    public int deleteECertificationReviewByIds(Long[] ids)
    {
        return eCertificationReviewMapper.deleteECertificationReviewByIds(ids);
    }

    /**
     * 删除认证审核信息
     *
     * @param id 认证审核主键
     * @return 结果
     */
    @Override
    public int deleteECertificationReviewById(Long id)
    {
        return eCertificationReviewMapper.deleteECertificationReviewById(id);
    }


    /*
    * 审核通过
    * */
    @Override
    public int approvalCertificationReviewStatus(Long id) {
        ECertificationReview eCertificationReview = eCertificationReviewMapper.selectECertificationReviewById(id);
        if(eCertificationReview.getCertificationType()==1){
            EPersonnel ePersonnel = ePersonnelMapper.selectEPersonnelById(eCertificationReview.getPid());
            ePersonnel.setRealNameAuthenticationStatus(Long.valueOf(1));
            ePersonnelMapper.updateEPersonnel(ePersonnel);
        }
        return eCertificationReviewMapper.approvalCertificationReviewStatus(id);
    }


    /*
    * 审核拒绝
    * */
    @Override
    public int rejectCertificationReviewStatus(ECertificationReview eCertificationReview) {
        return eCertificationReviewMapper.rejectCertificationReviewStatus(eCertificationReview);
    }

    /*
    * 根据认证审核的外键查询快递员认证审核的详细信息
    * */
    @Override
    public ECertificationReview selectCourierCertificationReviewByPid(Long pid) {
        return eCertificationReviewMapper.selectCourierCertificationReviewByPid(pid);
    }

    /*
    * 根据认证审核的外键查询实名认证的详细信息
    * */
    @Override
    public ECertificationReview selectRealNameCertificationReviewByPid(Long pid) {
        return eCertificationReviewMapper.selectRealNameCertificationReviewByPid(pid);
    }
}
